# 导包
import requests
# 封装员工管理接口类
from common.Authorization_date import ihrmAuthorization


class empManage:
    # 封装员工添加接口
    @classmethod
    def emp_insert(cls,herderJson,jsonData):
        # data = ihrmLogin.ihrm_login('13800000002', '123456').json()['data']
        # herderData = {"Content-Type": "application/json", "Authorization": data}
        # jsonData = {"username": name, "mobile": mobile, "workNumber": num}
        # resp = requests.post(url='http://ihrm2-test.itheima.net/api/sys/user',
        #                       headers=herderData,
        #                       json=jsonData)
        resp = requests.post(url='http://ihrm2-test.itheima.net/api/sys/user',
                             headers=herderJson,
                             json=jsonData)

        return resp


    # 封装员工修改接口
    @classmethod
    def emp_update(cls,dataId,herderJson,jsonData):
        # dataID = emp_insert.ihrm_emp_insert('张大大33', mobile, '12343554').json()['data']['id']
        # herderData = {"Content-Type": "application/json", "Authorization": cls.data}
        # URL = 'http://ihrm2-test.itheima.net/api/sys/user/' + dataID
        # jsonData = {"username": "张小花33"}
        resp = requests.put(url='http://ihrm2-test.itheima.net/api/sys/user/' + dataId,
                            headers=herderJson, json=jsonData)
        return resp

    # 封装员工查询接口
    @classmethod
    def emp_select(cls,dataId,herderJson):
        # dataID = emp_insert.ihrm_emp_insert('张大大33', mobile, '12343554').json()['data']['id']
        # herderJson = {'Content-Type': 'application/json', "Authorization": cls.data}
        resp = requests.get(url='http://ihrm2-test.itheima.net/api/sys/user/' + dataId,
                            headers=herderJson)

    # 封装员工删除接口
    @classmethod
    def emp_del(cls,dataId,herderJson):
        # dataID = emp_insert.ihrm_emp_insert('张大大33', mobile, '12343554').json()['data']['id']
        # herderData = {"Content-Type": "application/json", "Authorization": cls.data}
        # URL = 'http://ihrm2-test.itheima.net/api/sys/user/' + dataID
        resp = requests.delete(url='http://ihrm2-test.itheima.net/api/sys/user/' + dataId,
                               headers=herderJson)
        return resp


if __name__ == '__main__':
    herderJson = {"Content-Type": "application/json", "Authorization": ihrmAuthorization()}
    jsonData = {"username": '张大大33', "mobile": "13343857457", "workNumber": "12343554"}
    resp = empManage.emp_insert(herderJson, jsonData)
    print(resp.json())
